package com.seres.data;

import java.util.List;

public class GameStructure {
	private int gameStructureId;
	private String structureName;
	
	private List<RiskModule> riskModules;
	private List<SHModule> shModules;
	private List<CoreModule> coreModules;
	
	GameStructure(){
		
	}
	public GameStructure(String structureName, List<RiskModule> riskModules, List<SHModule> shModules, List<CoreModule> coreModules){
		setStructureName(structureName);
		setRiskModules(riskModules);
		setSHModules(shModules);
		setCoreModules(coreModules);
	}


	private boolean hasNextModule(List<? extends Module> modules){
		for (Module module : modules){
			if(!module.hasBeenFinished()){
				return true;
			}
		}
		return false;
	}
	private Module determineNextModule(List<? extends Module> modules){
		for (Module module : modules){
			if(!module.hasBeenFinished()){
				return module;
			}
		}
		return null;
	}
	
	public int getGameStructureId() {
		return gameStructureId;
	}
	public void setGameStructureId(int gameStructureId) {
		this.gameStructureId = gameStructureId;
	}
	public void setStructureName(String structureName) {
		this.structureName = structureName;
	}
	public String getStructureName() {
		return structureName;
	}
	
	private void setRiskModules(List<RiskModule> riskModules) {
		this.riskModules = riskModules;
	}
	private List<RiskModule> getRiskModules() {
		return riskModules;
	}
	public boolean hasNextRiskModule(){
		return hasNextModule(getRiskModules());
	}
	public RiskModule getNextRiskModule(){
		return (RiskModule) determineNextModule(getRiskModules());
	}
	
	private void setSHModules(List<SHModule> shModules) {
		this.shModules = shModules;
	}
	private List<SHModule> getSHModules() {
		return shModules;
	}
	public boolean hasNextSHModule(Stakeholder stakeholder){
		for (SHModule module : getSHModules()){
			if(!module.hasBeenFinished() && module.getStakeholder() == stakeholder){
				return true;
			}
		}
		return false;
	}
	public SHModule getNextSHModule(Stakeholder stakeholder){
		for (SHModule module : getSHModules()){
			if(!module.hasBeenFinished() && module.getStakeholder() == stakeholder){
				return module;
			}
		}
		return null;
	}
	
	public void setCoreModules(List<CoreModule> coreModules) {
		this.coreModules = coreModules;
	}
	private List<CoreModule> getCoreModules() {
		return coreModules;
	}
	public boolean hasNextCoreModule(){
		return hasNextModule(getCoreModules());
	}
	public CoreModule getNextCoreModule(){
		return (CoreModule) determineNextModule(getCoreModules());
	}
	public int getNumberOfCoreModules(){
		return getCoreModules().size();
	}
	public int getNumberOfFinishedCoreModules(){
		int nrOfFinishedModules = 0;
		
		for(Module coreMod : getCoreModules()){
			if(coreMod.hasBeenFinished()){
				nrOfFinishedModules++;
			}
		}

		return nrOfFinishedModules;
	}
	public int getNumberOfFinishedSHModules(){
		int nrOfFinishedModules = 0;
		
		for(Module shMod : getSHModules()){
			if(shMod.hasBeenFinished()){
				nrOfFinishedModules++;
			}
		}

		return nrOfFinishedModules;
	}
	public int getNumberOfFinishedRiskModules(){
		int nrOfFinishedModules = 0;
		
		for(Module riskMod : getRiskModules()){
			if(riskMod.hasBeenFinished()){
				nrOfFinishedModules++;
			}
		}

		return nrOfFinishedModules;
	}
	public int getNumberOfFinishedModules(){
		return getNumberOfFinishedCoreModules() + getNumberOfFinishedSHModules() + getNumberOfFinishedRiskModules();
	}
}
